﻿Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Configuration.ConfigurationSettings


Public Class DataProcessor

    Private _FiscalYear As Integer
    Private _FiscalPeriod As Integer

    Sub New(ByVal fy As Integer, ByVal fp As Integer)
        _FiscalYear = fy
        _FiscalPeriod = fp
    End Sub
    Property FiscalYear() As Integer
        Get
            Return _FiscalYear
        End Get
        Set(ByVal Value As Integer)
            _FiscalYear = Value
        End Set
    End Property


    Property FiscalPeriod() As Integer
        Get
            Return _FiscalPeriod
        End Get
        Set(ByVal Value As Integer)
            _FiscalPeriod = Value
        End Set
    End Property

    'Sub ProcessData(ByVal fiscalPeriod As Int16, ByVal fiscalYear As Int16)
    Function ProcessData() As Integer
        '5 Data files produced by Scheduled STAR reports.  They are FTP'd via 
        'scheduled bat file on pppReport (sql server's home) to it's c:\data\ 
        'directory from which I can then import them into sql server via OpenRowset
        Dim intReturnValue As Int16

        'Dim constringSqlServer As String = My.Settings.ConnString
        Dim constringSqlServer As String = My.Settings.FinRptConnectionString
        Try
            'Because of the using statement Close is called automatically:
            Using connection As New SqlConnection(constringSqlServer)
                Dim command As New SqlCommand("FinRptLoadCrunch", connection)
                command.Parameters.Add("@FiscalPeriod", SqlDbType.Int, 4).Value = fiscalPeriod
                command.Parameters.Add("@FiscalYear", SqlDbType.Int, 4).Value = fiscalYear

                command.Connection.Open()
                'if you are calling stored procedures in the plain vanilla way, 
                'don't have to worry about synchronization, as calls to SQL Server 
                'are synchronous
                intReturnValue = command.ExecuteNonQuery()
            End Using

        Catch SQLexc As SqlException
            'ExceptionManager.Publish(SQLexc)
            MsgBox(SQLexc.ToString())
        Finally
        End Try
        Return (intReturnValue)
    End Function




End Class
